﻿#ifndef IMAGEITEM_H
#define IMAGEITEM_H
#include <QGraphicsItem>
#include <QPainter>
//#include "JistCommonModel.h"
class JistCommonData;
// 좌표 정렬하기
#define X1 (960/4)
//#define X2 (960/4 * 1.5)
#define X3 (960/4 * 3)
#define Y1 (640/4)
#define Y2 (640/4 * 2)
#define Y3 (640/4 * 3)
#define OPPOSIT_SPACE (368)
extern int X2;

class ImageItem: public QGraphicsRectItem, public QObject
{
public:

//    QImage m_buffer;
//    QImage m_base_buffer;

    int m_composition_mode;
    bool m_FlipH;
    bool m_FlipV;

    //ImageItem( const QImage *img, QVector< QList < JistCommonData> > *spriteData = NULL, int oX = 2, int oY = 0 );
    ImageItem(int imgId, int spriteId, QVector< QList < JistCommonData> > *spriteData, int oX = 2, int oY = 0 );
    //ImageItem();
    QImage m_Image;
    QImage *m_SrcImage;
    QImage m_ResultImage;
    QImage m_ConculusionImg;
    QPoint m_OriginPos;
    int m_oIndex_X;
    int m_oIndex_Y;
    int m_iImageId;
    int m_iSpriteId;
    QVector< QList < JistCommonData> > &m_SpriteData;
    QPoint m_RelativePos;
    bool m_bEffDraw;
    qreal m_Scale;
    QSizeF m_ScaleXY;
    ~ImageItem() {}
    void setOriginPos(int index_X, int index_Y);
    void init();
    void setPosInit();
    void setOriginPosInit(int index_X, int index_Y);
    void setOriginPosInit();
    void setRelativePos();
    QPoint getRelativePos();
    void setPos(const QPointF & pos);
    void setPos(qreal ax, qreal ay);
    void setScale ( qreal factor );
    void setScaleX(qreal factor);
    void setScaleY(qreal factor);
    qreal scale () const;
    QSizeF scaleXY () const;
    void setRotation ( qreal angle );
    qreal rotation () const;
    void setId(int id);
    int getId();
    void updateRect(qreal ax, qreal ay, qreal w, qreal h);
    QImage getImage() { return m_Image; }
    qreal m_Angle;
    qreal m_Modscale;
    QSize m_ModifySize;
    QGraphicsTextItem *m_TextItem;
    char m_iAnchor;

    // !!!!TableView and ImageItem synchronizing selecting!!!
    int m_Id;

protected:
    void paint( QPainter *, const QStyleOptionGraphicsItem *option, QWidget *widget );
private:
    QPixmap pixmap;

public slots:
//    void setClearMode() { m_composition_mode = QPainter::CompositionMode_Clear; update(); }
//    void setSourceMode() { m_composition_mode = QPainter::CompositionMode_Source; update(); }
//    void setDestMode() { m_composition_mode = QPainter::CompositionMode_Destination; update(); }
//    void setSourceOverMode() { m_composition_mode = QPainter::CompositionMode_SourceOver; update(); }
//    void setDestOverMode() { m_composition_mode = QPainter::CompositionMode_DestinationOver; update(); }
//    void setSourceInMode() { m_composition_mode = QPainter::CompositionMode_SourceIn; update(); }
//    void setDestInMode() { m_composition_mode = QPainter::CompositionMode_DestinationIn; update(); }
//    void setSourceOutMode() { m_composition_mode = QPainter::CompositionMode_SourceOut; update(); }
//    void setDestOutMode() { m_composition_mode = QPainter::CompositionMode_DestinationOut; update(); }
//    void setSourceAtopMode() { m_composition_mode = QPainter::CompositionMode_SourceAtop; update(); }
//    void setDestAtopMode() { m_composition_mode = QPainter::CompositionMode_DestinationAtop; update(); }
//    void setXorMode() { m_composition_mode = QPainter::CompositionMode_Xor; update(); }

//    void setPlusMode() { m_composition_mode = QPainter::CompositionMode_Plus; update(); }
//    void setMultiplyMode() { m_composition_mode = QPainter::CompositionMode_Multiply; update(); }
//    void setScreenMode() { m_composition_mode = QPainter::CompositionMode_Screen; update(); }
//    void setOverlayMode() { m_composition_mode = QPainter::CompositionMode_Overlay; update(); }
//    void setDarkenMode() { m_composition_mode = QPainter::CompositionMode_Darken; update(); }
//    void setLightenMode() { m_composition_mode = QPainter::CompositionMode_Lighten; update(); }
//    void setColorDodgeMode() { m_composition_mode = QPainter::CompositionMode_ColorDodge; update(); }
//    void setColorBurnMode() { m_composition_mode = QPainter::CompositionMode_ColorBurn; update(); }
//    void setHardLightMode() { m_composition_mode = QPainter::CompositionMode_HardLight; update(); }
//    void setSoftLightMode() { m_composition_mode = QPainter::CompositionMode_SoftLight; update(); }
//    void setDifferenceMode() { m_composition_mode = QPainter::CompositionMode_Difference; update(); }
//    void setExclusionMode() { m_composition_mode = QPainter::CompositionMode_Exclusion; update(); }

    void recalculateResult();
    void update();
};


#endif // IMAGEITEM_H
